132
Beginner’s Guide to Code Algorithms
132
FIGURE 9.1 VBA References.
9.4 THE ALGORITHM
This is a simple program where we could identify the fields on the web page easily
using just the class attribute. There are others that are more complex, and the field
can be identified by alternative attributes. Some of these attributes are the id, the tag
name, etc. These have not been covered here, but you are likely to need them when
you deal with more complex web pages—google is probably one of the simplest by
design, since it is a universal search application where most of its complexity resides
on the server end.
The code for this algorithm is here:
STEP 1
Initialize variables and launch the website
Sub ScrapeWebsiteCurrency()
Dim ie As Object
Dim form As Variant
Dim button As Variant
Dim LR, RateRow As Integer
Dim var As String
Dim var1 As Object
Dim oHEle As HTMLUListElement ‘ Create HTML element (<ul>) object.
LR = Worksheets(“Currency Pairs”).Cells(Rows.Count, 1).End(xlUp).Row
RateRow = Worksheets(“Currency Rates”).Cells(Rows.Count, 1).End(xlUp).Row
Set ie = CreateObject(“internetexplorer.application”)
ie.Visible = True
With ie
.Visible = True
.navigate “google.com/”
While Not .readyState = READYSTATE_COMPLETE